home *** CD-ROM | disk | FTP | other *** search
Wrap
//Mark Sobota //John Hawkins //defensive.bhs //rush script //works for each nation labels { BLOCK_ON_THIS = 1, DONT_BLOCK_ON_THIS, SCRIPT_DONE, } include "aibestbuildlibrary.bhs" int ai defensive (int who, ref int step, int boom_vs_rush, int num_loops) { if ((num_cities(who) < 1)&&(num_type_with_queued(who, "Citizen") < 1)) return SCRIPT_DONE; my_capital = find_city_with_num(who, 1); if (was_city_attacked(who, "", -1)||was_city_raided(who, "", -1)) { if ((num_type_with_queued(who, "Barracks") < 1)&&(have_tech(who, "The Art of War"))) { if (place_building_with_cost(who, "Barracks", my_capital) > 0) return SCRIPT_DONE; else return BLOCK_ON_THIS; } else return SCRIPT_DONE; } int return_value = BLOCK_ON_THIS; static int prev_step0 = 0; static int prev_step1 = 0; static int prev_step2 = 0; static int prev_step3 = 0; static int prev_step4 = 0; static int prev_step5 = 0; static int prev_step6 = 0; static int prev_step7 = 0; static int needed_citizens0 = 0; static int needed_citizens1 = 0; static int needed_citizens2 = 0; static int needed_citizens3 = 0; static int needed_citizens4 = 0; static int needed_citizens5 = 0; static int needed_citizens6 = 0; static int needed_citizens7 = 0; static int rush_build0 = rand_int(1, 10); static int rush_build1 = rand_int(1, 10); static int rush_build2 = rand_int(1, 10); static int rush_build3 = rand_int(1, 10); static int rush_build4 = rand_int(1, 10); static int rush_build5 = rand_int(1, 10); static int rush_build6 = rand_int(1, 10); static int rush_build7 = rand_int(1, 10); static int timer_started0 = 0; static int timer_started1 = 0; static int timer_started2 = 0; static int timer_started3 = 0; static int timer_started4 = 0; static int timer_started5 = 0; static int timer_started6 = 0; static int timer_started7 = 0; static int fishermen_total0 = 0; static int fishermen_total1 = 0; static int fishermen_total2 = 0; static int fishermen_total3 = 0; static int fishermen_total4 = 0; static int fishermen_total5 = 0; static int fishermen_total6 = 0; static int fishermen_total7 = 0; int old_step; who_nation = find_nation(who); //get player nation static int needed_techs = get_techs_per_age(who); int player_age = age(who); static int wood_camp = 0; static int wood_camp_1 = 0; static int max_woodcutters = 0; int needed_citizens = 0; static int build_merchant = 0; int timer_started = 0; int j = 0; int k = 0; int build_true = 0; int new_city = 0; int citizen_id = 0; int caravan_lim = num_cities(who) * (num_cities(who) - 1) / 2; int fishermen_cap = 4; int fishermen_total = 0; int large_conquest_start = 0; int sea_map = 0; int rush_build = 0; ///ghetto array/// switch (who-1) { case 0: old_step = prev_step0; needed_citizens = needed_citizens0; rush_build = rush_build0; timer_started = timer_started0; fishermen_total = fishermen_total0; break; case 1: old_step = prev_step1; needed_citizens = needed_citizens1; rush_build = rush_build1; timer_started = timer_started1; fishermen_total = fishermen_total1; break; case 2: old_step = prev_step2; needed_citizens = needed_citizens2; rush_build = rush_build2; timer_started = timer_started2; fishermen_total = fishermen_total2; break; case 3: old_step = prev_step3; needed_citizens = needed_citizens3; rush_build = rush_build3; timer_started = timer_started3; fishermen_total = fishermen_total3; break; case 4: old_step = prev_step4; needed_citizens = needed_citizens4; rush_build = rush_build4; timer_started = timer_started4; fishermen_total = fishermen_total4; break; case 5: old_step = prev_step5; needed_citizens = needed_citizens5; rush_build = rush_build5; timer_started = timer_started5; fishermen_total = fishermen_total5; break; case 6: old_step = prev_step6; needed_citizens = needed_citizens6; rush_build = rush_build6; timer_started = timer_started6; fishermen_total = fishermen_total6; break; case 7: old_step = prev_step7; needed_citizens = needed_citizens7; rush_build = rush_build7; timer_started = timer_started7; fishermen_total = fishermen_total7; break; default: old_step = 0; needed_citizens = 0; break; } //turns off ancient age rush for certain rules if ((get_rush_rules() > 0)||(is_victory_economic())||(is_victory_musical_chairs())||(is_victory_tech_race())||(is_victory_territory())||(is_victory_wonder())||(is_victory_score())) { rush_build = 20; } ////water mapstyles at the moment: Atlantic Sea Power, Nile Delta, British Isles, Warring States, New World, East Indies ////East Meets West, Colonial Powers, Mediterranean, Australian Outback ////not at the moment: Great Lakes?, African Watering Hole? if ((get_mapstyle() == "Atlantic Sea Power")||(get_mapstyle() == "Nile Delta")||(get_mapstyle() == "British Isles")||(get_mapstyle() == "Warring States")||(get_mapstyle() == "New World")||(get_mapstyle() == "East Indies")) { sea_map = 1; } else if ((get_mapstyle() == "East Meets West")||(get_mapstyle() == "Colonial Powers")||(get_mapstyle() == "Mediterranean")||(get_mapstyle() == "Australian Outback")) { sea_map = 1; } else sea_map = 0; my_second_city = find_city_with_num(who, 2); my_third_city = find_city_with_num(who, 3); if (is_conquest_scenario()) { size = get_starting_town_size(who); if (step == 1) { if (size == 0) step = 1; //nomad else if (size == 1) step = 2; else if (size == 2) step = 6; //standard else large_conquest_start = 1; } else if (size > 2) large_conquest_start = 1; } if (large_conquest_start > 0) { if ((age(who) > 0)&&(age(who) < 5)) { //build 2 farms, university, mine, 2nd woodcutter, research military 1, build barracks, build stable, 2 heavy, 2 light, 1 archer switch (step) { case 1: if(!have_tech(who, "The Art of War")) { if (research_tech_with_cost(who, "The Art of War") > 0) step++; } else step++; return BLOCK_ON_THIS; break; case 2: train_unit_with_cost(who, 5, "Citizen"); if (have_tech(who, "The Art of War")) step+=2; else step++; return BLOCK_ON_THIS; break; case 3: if (num_type_with_queued(who, "Barracks") < 1) { if (num_cities(who) == 1) place_building_upgrade_with_cost(who, "Barracks", my_capital); else if (num_cities(who) == 2) place_building_upgrade_with_cost(who, "Barracks", my_second_city); else if (num_cities(who) == 3) place_building_upgrade_with_cost(who, "Barracks", my_third_city); } if (num_type_with_queued(who, "Stable") < 1) { if (num_cities(who) == 1) place_building_upgrade_with_cost(who, "Stable", my_capital); else if (num_cities(who) == 2) place_building_upgrade_with_cost(who, "Stable", my_second_city); else if (num_cities(who) == 3) place_building_upgrade_with_cost(who, "Stable", my_third_city); } if ((num_type_with_queued(who, "Barracks") > 0)&&(num_type_with_queued(who, "Stable") > 0)) step++; return BLOCK_ON_THIS; break; case 4: if (num_type_with_queued(who, "Tower") < num_cities(who)) { if (num_cities(who) == 1) place_building_upgrade_with_cost(who, "Tower", my_capital); else if (num_cities(who) == 2) { place_building_upgrade_with_cost(who, "Tower", my_second_city); place_building_upgrade_with_cost(who, "Tower", my_capital); } else if (num_cities(who) == 3) { place_building_upgrade_with_cost(who, "Tower", my_third_city); place_building_upgrade_with_cost(who, "Tower", my_second_city); place_building_upgrade_with_cost(who, "Tower", my_capital); } } else if (num_type(who, "Market") < 1) return SCRIPT_DONE; if (num_type_with_queued(who, "Tower") > num_cities(who)-1) return SCRIPT_DONE; return BLOCK_ON_THIS; break; default: return SCRIPT_DONE; } } else if (age(who) > 4) { switch (step) { case 1: if(!have_tech(who, "The Art of War")) { if (research_tech_with_cost(who, "The Art of War") > 0) step++; } else step++; return BLOCK_ON_THIS; break; case 2: train_unit_with_cost(who, 5, "Citizen"); if (have_tech(who, "The Art of War")) step+=2; else step++; return BLOCK_ON_THIS; break; case 3: if (num_type_with_queued(who, "Barracks") < 1) { if (num_cities(who) == 1) place_building_upgrade_with_cost(who, "Barracks", my_capital); else if (num_cities(who) == 2) place_building_upgrade_with_cost(who, "Barracks", my_second_city); else if (num_cities(who) == 3) place_building_upgrade_with_cost(who, "Barracks", my_third_city); } if (num_type_with_queued(who, "Auto Plant") < 1) { if (num_cities(who) == 1) place_building_upgrade_with_cost(who, "Auto Plant", my_capital); else if (num_cities(who) == 2) place_building_upgrade_with_cost(who, "Auto Plant", my_second_city); else if (num_cities(who) == 3) place_building_upgrade_with_cost(who, "Auto Plant", my_third_city); } if ((num_type_with_queued(who, "Barracks") > 0)&&(num_type_with_queued(who, "Auto Plant") > 0)) step++; return BLOCK_ON_THIS; break; case 4: if (num_type_with_queued(who, "Stockade") < num_cities(who)) { if (num_cities(who) == 1) place_building_upgrade_with_cost(who, "Tower", my_capital); else if (num_cities(who) == 2) { place_building_upgrade_with_cost(who, "Tower", my_second_city); place_building_upgrade_with_cost(who, "Tower", my_capital); } else if (num_cities(who) == 3) { place_building_upgrade_with_cost(who, "Tower", my_third_city); place_building_upgrade_with_cost(who, "Tower", my_second_city); place_building_upgrade_with_cost(who, "Tower", my_capital); } } else if (num_type(who, "Market") < 1) return SCRIPT_DONE; if (num_type_with_queued(who, "Tower") > num_cities(who)-1) return SCRIPT_DONE; return BLOCK_ON_THIS; break; default: return SCRIPT_DONE; } } } //checks to see what the settings are and initializes the script starting point to the appropriate place if (step == 1) { if (get_starting_resources(who) > 4 || num_cities(who) > 1) { return SCRIPT_DONE; } size = get_starting_town_size(who); if (size == 0) step = 1; //nomad else if (size == 1) step = 2; else if (size >= 2) step = 6; //standard else return SCRIPT_DONE; } //trains citizens if the need isn't currently fulfilled if (needed_citizens > 0) train_unit_with_need(who, needed_citizens, "Citizen"); ////builds needed number of caravans and merchants if (num_type(who, "Market") >= 1) { if (num_type_with_queued(who, "Caravan") < caravan_lim) { train_unit_with_cost(who, 1, "Caravan"); } for (j = num_type_with_queued(who, "Merchant"); ((j < 3)&&(j < num_rare_resources_seen(who))); j++) { if (train_unit_with_cost(who, 1, "Merchant") < 1) break; } } ////builds farms until limit is reached ////check to see map style and place dock at second city and start 2 boats up if appropriate if (step > 16) { if ((who_nation == "Germans")&&(get_is_no_nation_powers() < 1)) { if (num_city_buildings(who, my_capital, "Granary", 1) < 1) { place_building_with_cost(who, "Granary", my_capital); } if (num_city_buildings(who, my_capital, "Lumber Mill", 1) < 1) { place_building_with_cost(who, "Lumber Mill", my_capital); } } if (sea_map > 0) { if (num_type_with_queued(who, "Dock") < 1) { place_dock(who); //tries to place a dock near a city in this order: Capital, City Two, City Three } else { //train two initial fish herders if (fishermen_total < 2) { if (train_unit_with_cost(who, 1, "Fishermen") > 0) fishermen_total++; } } } //fill up first two cities with farms if (place_farm(who) > 0) old_step = 0; } //after market is built, train as many fish herders as possible before classical age if ((fishermen_total < fishermen_cap)&&(step > 20)&&(step < 27)&&(num_type(who, "Dock") > 0)) { if (train_unit_with_cost(who, 1, "Fishermen") > 0) fishermen_total++; } //if population is approaching the limit we need to research the first military tech if (population(who) >= 23 && (!have_tech(who, "The Art of War"))) { research_tech_with_cost(who, "The Art of War"); } //Ancient Age Rush part, only happens a third of the time if ((step == 6)&&(rush_build < 4)&&(!is_conquest_scenario())&&(sea_map < 1)&&(get_starting_town_size(who) > 1)) { old_step = 0; if(!have_tech(who, "The Art of War")) { while (num_city_buildings(who, my_capital, "Farm", 1) < 5) { if (place_building_with_cost(who, "Farm", my_capital) < 1) break; } if (research_tech_with_cost(who, "The Art of War") > 0) { needed_citizens = 9; train_unit_with_need(who, needed_citizens, "Citizen"); return BLOCK_ON_THIS; } else return BLOCK_ON_THIS; } else { if (num_type_with_queued(who, "Barracks") < 1) { place_building_with_cost(who, "Barracks", my_capital); return BLOCK_ON_THIS; } else if (num_type(who, "Barracks") > 0) { //build 4 heavies and one light if (num_type_with_queued(who, "Hoplites") < 4) { train_unit_with_cost(who, 1, "Hoplites"); return BLOCK_ON_THIS; } else if (num_type_with_queued(who, "Slingers") < 1) { train_unit_with_cost(who, 1, "Slingers"); return BLOCK_ON_THIS; } else { rush_build = 25; return_value = BLOCK_ON_THIS; } } else return BLOCK_ON_THIS; } } ////check to see if script is hanging if ((step == old_step)&&(timer_started < 1)) { set_timer(who, 240); timer_started = 1; } if (step != old_step) { stop_timer(who); timer_started = 0; } if (timer_expired(who)) { return SCRIPT_DONE; } for (i = 0; i < num_loops; i++) { if (old_step != step) old_step = step; switch (step) { ////Nomad Setup Procedure///// case 1: //place City (nomad) old_step = 0; if (num_type_with_queued(who, "Small City") < 1) place_city_with_cost(who); if (find_inactive_build(who, "Small City")) { new_city = find_inactive_build(who, "Small City"); if (building_started(who, new_city)) step++; } return_value = BLOCK_ON_THIS; break; case 2: //place Woodcutter's Camp at capital old_step = 0; new_city = find_inactive_build(who, "Small City"); if (new_city > 0) { for (j = 0; j < num_type(who, "Citizen"); j++) { citizen_id = find_unit(who, "Citizen"); citizen_repair_order(who, citizen_id, new_city); } } if (place_building_with_cost(who, "Woodcutter's Camp", my_capital) > 0) step++; else if ((my_capital > -1) && (can_pay_cost(who, "Woodcutter's Camp") > 0)) return SCRIPT_DONE; return_value = BLOCK_ON_THIS; break; case 3: //place 3 farms at capital old_step = 0; for (j = num_type_with_queued(who, "Farm"); j < 3; j++) { if (place_building_with_cost(who, "Farm", my_capital) < 1) break; } if (num_type_with_queued(who, "Farm") == 3) step++; return_value = BLOCK_ON_THIS; break; case 4: //build up to 5 peasants needed_citizens = 5; train_unit_with_need(who, needed_citizens, "Citizen"); step++; return_value = BLOCK_ON_THIS; break; case 5: //build a library old_step = 0; if (place_building_with_cost(who, "Library", my_capital) > 0) step++; return_value = BLOCK_ON_THIS; break; ////End Nomad Setup Procedure///// case 6: //research first science tech old_step = 0; if (have_tech(who, "Written Word")) step++; else if (research_tech_with_cost(who, "Written Word") > 0) step++; else if (at_least_type(who, 75, "Wealth") < 1) { if (sea_map > 0) return SCRIPT_DONE; else step++; } return_value = BLOCK_ON_THIS; break; case 7: //place farm #4 if (num_city_buildings(who, my_capital, "Farm", 1) < 4) { if (place_building_with_cost(who, "Farm", my_capital) > 0) { if ((age(who) > 0) || ((who_nation == "Greeks")&&(get_is_no_nation_powers() < 1))) step++; else step+=2; } } else { if ((age(who) > 0) || ((who_nation == "Greeks")&&(get_is_no_nation_powers() < 1))) step++; else step+=2; } return_value = BLOCK_ON_THIS; break; case 8: //place university at capital if (num_type(who, "University") < 1) { if (place_building_with_cost(who, "University", my_capital) > 0) step++; } else step++; return_value = BLOCK_ON_THIS; break; case 9: //research first Civics tech if (num_cities(who) > 1) return SCRIPT_DONE; else if (have_tech(who, "City State")) step++; else if (research_tech_with_cost(who, "City State")) step++; return_value = BLOCK_ON_THIS; break; case 10: //build 6th-8th citizen train_unit_with_cost(who, 3, "Citizen"); step++; return_value = BLOCK_ON_THIS; break; case 11: //place second_city if (have_tech(who, "City State")) { if (num_cities(who) < 2) { if (city_placement(who) > 0) step++; else if (can_pay_cost(who, "Small City")) step++; } else step++; } return_value = BLOCK_ON_THIS; break; case 12: //build 9th-10th citizen needed_citizens = 10; train_unit_with_need(who, needed_citizens, "Citizen"); step++; return_value = BLOCK_ON_THIS; break; case 13: //place farm #5 if (num_type_with_queued(who, "Farm") < 5) { place_building_with_cost(who, "Farm", my_capital); step++; } else step++; return_value = BLOCK_ON_THIS; break; case 14: //place a second woodcutter's camp if 2nd is 5 or less if (place_woodcutter(who) > 0) step++; else if (can_pay_cost(who, "Woodcutter's Camp") > 0) step++; return_value = BLOCK_ON_THIS; break; case 15: //research first commerce tech if (research_tech_with_cost(who, "Barter") > 0){ if ((age(who) > 0) || ((who_nation == "Greeks")&&(get_is_no_nation_powers() < 1))) step++; else step+=2; } return_value = BLOCK_ON_THIS; break; case 16: // build 1 scholars (if possible) if (num_type(who, "University") >= 1) { if (train_unit_with_cost(who, 1, "Scholar") > 0) step++; } else step++; return_value = BLOCK_ON_THIS; break; case 17: //build 12th-16th citizen needed_citizens = 16; train_unit_with_need(who, needed_citizens, "Citizen"); if ((who_nation == "British")&&(get_is_no_nation_powers() < 1)) { step+=2; } else step++; return_value = BLOCK_ON_THIS; break; case 18: //research second commerce tech if (num_cities(who) < 2) return SCRIPT_DONE; if (research_tech_with_cost(who, "Coinage") >= 0) old_step = 0; if (have_tech(who, "Coinage")) step++; return_value = BLOCK_ON_THIS; break; case 19: //train citizen 17-20, place third city if bantu needed_citizens = 20; train_unit_with_need(who, needed_citizens, "Citizen"); if (num_cities(who) < 2) { //checks to see if the second city wasn't placed initially if (sea_map > 0) { //places second city on island(in theory) if second city hasn't been placed if (num_type(who, "Dock") > 0) { if (city_placement(who) > 0) step++; else if (can_pay_cost(who, "Small City") > 0) step++; } } else step++; } else { if ((who_nation == "Bantu")&&(get_is_no_nation_powers() < 1)) { if (num_cities(who) < 3) { if (sea_map > 0) { if (num_type(who, "Dock") > 0) { if (city_placement(who) > 0) step++; else if (can_pay_cost(who, "Small City")) step++; } else if ((num_type_with_queued(who, "Dock") < 1)&&(can_pay_cost(who, "Dock") > 0)) { if (city_placement(who) > 0) step++; else if (can_pay_cost(who, "Small City")) step++; } } else if (city_placement(who) > 0) step++; else if (can_pay_cost(who, "Small City")) step++; } else step++; } else { if ((who_nation == "Nubians")&&(get_is_no_nation_powers() < 1)) { step+=2; } else step++; } } return_value = BLOCK_ON_THIS; break; case 20: //build a market in capital if (num_type(who, "Market") == 0) { if (have_tech(who, "Barter")) { if (place_building_with_cost(who, "Market", my_capital) > 0) { if ((age(who) > 0) || ((who_nation == "Greeks")&&(get_is_no_nation_powers() < 1))) step++; else step+=2; } } } else { if ((age(who) > 0) || ((who_nation == "Greeks")&&(get_is_no_nation_powers() < 1))) step++; else step+=2; } return_value = BLOCK_ON_THIS; break; case 21: //build scholars 2 and 3 if (num_type(who, "University") >= 1) { if (train_unit_with_cost(who, 2, "Scholar") > 0) step++; } else step++; return_value = BLOCK_ON_THIS; break; case 22: //train citizen 21 needed_citizens = 21; train_unit_with_need(who, needed_citizens, "Citizen"); step++; return_value = BLOCK_ON_THIS; break; case 23: //build 3rd woodcutter's camp max_woodcutters = 0; for (wc = num_type(who, "Woodcutter's Camp"); wc > 0; wc--) { wood_camp = find_build(who, "Woodcutter's Camp"); max_woodcutters += max_workers_at_building(who, wood_camp); } if (max_woodcutters < 12) { if (find_inactive_build(who, "Woodcutter's Camp") > 0) step++; else { //only try this once place_woodcutter(who); step++; } } else step++; return_value = BLOCK_ON_THIS; break; case 24: //train citizen 22 needed_citizens = 22; train_unit_with_need(who, needed_citizens, "Citizen"); if (!have_tech(who, "The Art of War")) step++; else { if ((who_nation == "British")&&(get_is_no_nation_powers() < 1)) step+=3; else step+=2; } return_value = BLOCK_ON_THIS; break; case 25: //research first military tech if (!have_tech(who, "The Art of War")) { if (research_tech_with_cost(who, "The Art of War")) { if ((who_nation == "British")&&(get_is_no_nation_powers() < 1)) { step+=2; } else step++; } } else { if ((who_nation == "British")&&(get_is_no_nation_powers() < 1)) { step+=2; } else step++; } return_value = BLOCK_ON_THIS; break; case 26: //train citizens 23-25 needed_citizens = 25; train_unit_with_need(who, needed_citizens, "Citizen"); step++; return_value = BLOCK_ON_THIS; break; case 27: //barracks if (have_tech(who, "The Art of War")) { if (place_building_with_cost(who, "Barracks", my_second_city) > 0) step++; else if (place_building_with_cost(who, "Barracks", my_capital) > 0) step++; } return_value = BLOCK_ON_THIS; break; case 28: //tower if (place_building_with_cost(who, "Tower", my_second_city) > 0) step++; else if (place_building_with_cost(who, "Tower", my_capital) > 0) step++; return_value = BLOCK_ON_THIS; break; case 29: //research classical age if (is_conquest_scenario()) return SCRIPT_DONE; else if (needed_techs <= 3) { if (age(who) > 0) return SCRIPT_DONE; else if (research_tech_with_cost(who, "Classical Age") > 0) { return SCRIPT_DONE; } } else return SCRIPT_DONE; return_value = BLOCK_ON_THIS; break; default: return_value = SCRIPT_DONE; break; } } ///ghetto array/// switch (who-1) { case 0: prev_step0 = old_step; needed_citizens0 = needed_citizens; rush_build0 = rush_build; timer_started0 = timer_started; fishermen_total0 = fishermen_total; break; case 1: prev_step1 = old_step; needed_citizens1 = needed_citizens; rush_build1 = rush_build; timer_started1 = timer_started; fishermen_total1 = fishermen_total; break; case 2: prev_step2 = old_step; needed_citizens2 = needed_citizens; rush_build2 = rush_build; timer_started2 = timer_started; fishermen_total2 = fishermen_total; break; case 3: prev_step3 = old_step; needed_citizens3 = needed_citizens; rush_build3 = rush_build; timer_started3 = timer_started; fishermen_total3 = fishermen_total; break; case 4: prev_step4 = old_step; needed_citizens4 = needed_citizens; rush_build4 = rush_build; timer_started4 = timer_started; fishermen_total4 = fishermen_total; break; case 5: prev_step5 = old_step; needed_citizens5 = needed_citizens; rush_build5 = rush_build; timer_started5 = timer_started; fishermen_total5 = fishermen_total; break; case 6: prev_step6 = old_step; needed_citizens6 = needed_citizens; rush_build6 = rush_build; timer_started6 = timer_started; fishermen_total6 = fishermen_total; break; case 7: prev_step7 = old_step; needed_citizens7 = needed_citizens; rush_build7 = rush_build; timer_started7 = timer_started; fishermen_total7 = fishermen_total; break; default: old_step = 0; needed_citizens = 0; rush_build = 0; break; } return return_value; }